<?php
require_once ('conn.php');

$contactNumber = $_GET['contactNumber'];
$ci_contact = mysql_fetch_row(mysql_query("select id,number from ci_contact where number='$contactNumber' "));//获得网点信息

$times=time();//初始化一个时间
$number ="PD".date('YmdHis',$times).rand(10000,99999);//生成唯一订单号
$createTime = $times;//创建时间
$staffId=$_SESSION['userid'];//用户ID
$wdId = $ci_contact[0];//网点ID
$wdNumber = $ci_contact[1]; // 网点编号
$totalSku;// 商品总类
$totalQty = 0;//盘点数量
$status = 1;//状态
$remark = "移动端盘点数据";//备注

$sql="INSERT INTO ci_wd_inventory(
					number,
					createTime,
					staffId,
					wdId,
					wdNumber,
					status,
					remark
				)
					VALUES (
					'$number',
					'$createTime',
					$staffId,
					$wdId,
					'$wdNumber',
					$status,
					'$remark'
					)";
				if(mysql_query($sql)){//成功插入主表才做下一步
				foreach($_POST as $key=>$val){
					$goodsId = $key;
					$good = mysql_fetch_row(mysql_query("select number from ci_goods where id=$goodsId"));
					$goodsNumber =$good[0];
					$qty = $val;//盘点数量
					$totalQty = $totalQty + $val;//总表数量
					$sql2="INSERT INTO ci_wd_inventory_info(inventoryNumber,goodsId,goodsNumber,qty) VALUES ('$number',$goodsId,'$goodsNumber',$qty)";
					
					mysql_query($sql2);
					$i++;
		  }
        mysql_query("UPDATE ci_wd_inventory SET totalSku = $i, totalQty = $totalQty  where number='$number'");
	}
echo "<script>alert('盘点完成');window.location.href='supply_pandian.php'</script>";die;
?>